//对于axios的二次封装
import axios from "axios"
import nprogress from "nprogress"
import "nprogress/nprogress.css"

//利用axios对象的方法create,创建axios实例
const requests = axios.create({
    //基础路径，发送请求时路径会自动添加/api
    baseURL: '/mock',
    //请求超时时间5s
    timeout: 5000
})

//请求发送之前的处理的事务
requests.interceptors.request.use(
    (config) => {
        nprogress.start();
        return config
    }),
    (error) => {
        return Promise.reject(new Error('faile'))
    }


//响应结果接受之前的处理的事务
requests.interceptors.response.use(
    (res) => {
        nprogress.done();
        return res.data
    }),
    (error) => {
        return Promise.reject(new Error('faile'))
    }


export default requests